package com.koron.car.web.motorcade.controller;

import com.alibaba.fastjson.JSON;
import com.koron.bean.base.Response;
import com.koron.car.web.motorcade.bean.PrimaryOrg;
import com.koron.car.web.motorcade.service.PrimaryOrgService;
import com.koron.common.core.config.ThreadLocalContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (WCmPrimaryOrg)表控制层
 *
 * @author twcao
 * @since 2022-03-15 11:35:42
 */
@Slf4j
@RestController
@RequestMapping
@Api(tags = "车辆管理-基层组织")
public class PrimaryOrgController {
    /**
     * 服务对象
     */
    @Resource
    private PrimaryOrgService primaryOrgService;

    @GetMapping("/queryList")
    @ApiOperation("基层组织列表查询")
    public Response<List<PrimaryOrg>> queryList(PrimaryOrg query) {
        log.info("基层组织列表查询, query = {}", JSON.toJSONString(query));
        List<PrimaryOrg> bean = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), primaryOrgService, "queryList", List.class, query);
        return Response.ok(bean);
    }

    @PostMapping("/insertBatch")
    @ApiOperation("批量新增基层组织")
    public Response<Integer> insertBatch(@RequestBody List<PrimaryOrg> orgs) {
        log.info("修改基层组织名字, orgs = {}", JSON.toJSONString(orgs));
        int row = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), primaryOrgService, "insertOrUpdateBatch", Integer.class, orgs);
        return Response.ok(row);
    }
}
